package com.north.light.androidutils.canvas.examprogress.step;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.north.light.androidutils.R;

/**
 * FileName: ExamStepView
 * Author: lzt
 * Date: 2022/7/29 下午 3:13
 * 阶段图标类
 */
public class ExamStepView extends RelativeLayout {
    private TextView tvTitle;
    private ImageView ivCover;

    public ExamStepView(Context context) {
        super(context);
        init();
    }

    public ExamStepView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ExamStepView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        View rootView = LayoutInflater.from(getContext().getApplicationContext())
                .inflate(R.layout.view_do_exam_step_layout, null);
        addView(rootView);

        tvTitle = rootView.findViewById(R.id.tvStepName);
        ivCover = rootView.findViewById(R.id.tvStepImg);

    }

    /**
     * 设置
     */
    public void setInfo(ExamStepInfo info) {
        if (info == null) {
            return;
        }
        if (tvTitle != null) {
            tvTitle.setText(info.getTitle());
        }
        if (ivCover != null) {
            if (info.getStatus() == 1) {
                ivCover.setImageResource(info.getPassRes());
            } else {
                ivCover.setImageResource(info.getNoPassRes());
            }
        }
    }
}
